import 'package:sqflite/sqflite.dart';

import 'db_util.dart';

abstract class DBProvider {
  bool isTabExists = false;

  tableName();

  tableSqlString();

  tableBaseString(name, columnId) {
    return '''
      create table $name($columnId integer primary key autoincrement,
    ''';
  }

  Future<Database> getDB() async {
    return await open();
  }

  open() async {
    if (!isTabExists) {
      await prepare(tableName(), tableSqlString());
    }
    return await DBUtil.getCurrentDatabase();
  }

  prepare(name, sql) async {
    isTabExists = await DBUtil.isTableExists(name);
    if (!isTabExists) {
      Database db = await DBUtil.getCurrentDatabase();
      return await db.execute(sql);
    }
  }
}
